package me.zhengjie.modules.transformer.history.res;

import lombok.RequiredArgsConstructor;
import me.zhengjie.annotation.Log;
import me.zhengjie.modules.transformer.history.domain.FdsData;
import me.zhengjie.modules.transformer.history.service.FdsDataService;
import me.zhengjie.utils.FileUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.util.List;

/**
 * @author 陈佳豪
 * @website https://el-admin.vip
 * @date 2021-12-02
 **/
@RestController
@RequiredArgsConstructor
@Api(tags = "历史数据查询管理")
@RequestMapping("/api/transformer/fdsData")
public class FdsDataController {
    @Autowired
    FdsDataService fdsDataService;

    @PostMapping("/upload")
    @Log("导入一批数据")
    @ApiOperation("导入一批数据")
    public ResponseEntity<Object> upload(@RequestParam MultipartFile file) {
        File file1= FileUtil.toFile(file);
        fdsDataService.importFile(file1);
        return new ResponseEntity<>(HttpStatus.OK);
    }

    @GetMapping("/{recordId}")
    @Log("查询一批数据")
    @ApiOperation("查询一批数据")
    public ResponseEntity<Object> queryByRecordId(@PathVariable("recordId") int recordId) {
        List<FdsData> fdsDatas = fdsDataService.findByRecordId(recordId);
        return new ResponseEntity<>(fdsDatas, HttpStatus.OK);
    }

}